package com.seal.commons.infrastructure.redis.configuration;

import com.seal.commons.infrastructure.facade.distributed.limiter.DistributedRateLimiter;
import com.seal.commons.infrastructure.facade.distributed.lock.DistributedLock;
import com.seal.commons.infrastructure.redis.distributed.limiter.RedisDistributedRateLimiter;
import com.seal.commons.infrastructure.redis.distributed.lock.RedisDistributedLock;
import com.seal.commons.infrastructure.redis.configuration.redisson.RedissonAutoConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RedissonClient;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName:DistributedLockAutoConfiguration <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason:  TODO ADD REASON. <br/>
 * Date:     2019-04-15 17:27 <br/>
 *
 * @author yong.huang
 * @see
 * @since JDK 1.8
 */
@Configuration
@AutoConfigureAfter(RedissonAutoConfiguration.class)
@Slf4j
public class DistributedAutoConfiguration {


    @Bean("redisDistributedLock")
    @ConditionalOnBean(RedissonClient.class)
    public DistributedLock redisDistributedLock(RedissonClient redissonClient){
        return new RedisDistributedLock(redissonClient);
    }


    @Bean("redisDistributedRateLimiter")
    @ConditionalOnBean(RedissonClient.class)
    public DistributedRateLimiter redisDistributedRateLimiter(RedissonClient redissonClient){
        return new RedisDistributedRateLimiter(redissonClient);
    }

}